<template>
  <el-dialog
    v-model="dialogVisible"
    title="编辑排课信息"
    width="50%"
    :before-close="handleDialogClose"
  >
    <el-space fill wrap direction="horizontal" style="width: 100%">
      <el-card shadow="never" style="border: none">
        <div
          style="
            font-size: 16px;
            margin: 10px 0;
            font-weight: 600;
            line-height: 22px;
          "
        >
          {{ currentItem.className }}
        </div>
        <el-form :model="currentItem" label-width="75px">
          <el-form-item label="上课时间:">
            {{
              currentItem.weekNum
                ? currentItem.classDate.slice(0, 10) +
                  "(周" +
                  {
                    1: "一",
                    2: "二",
                    3: "三",
                    4: "四",
                    5: "五",
                    6: "六",
                    7: "日",
                  }[currentItem.weekNum] +
                  ")" +
                  "  " +
                  currentItem.classStartTime +
                  "~" +
                  currentItem.classEndTime
                : currentItem.classDate.slice(0, 10) +
                  "  " +
                  currentItem.classStartTime +
                  "~" +
                  currentItem.classEndTime
            }}
          </el-form-item>
          <el-form-item label="主班老师:"
            >{{ currentItem.teacherName }}
          </el-form-item>
          <el-form-item label="助教老师:"
            >{{ currentItem.assistantName }}
          </el-form-item>
          <el-form-item label="上课教室:"
            >{{ currentItem.classRoomName }}
          </el-form-item>
        </el-form>
      </el-card>

      <el-card shadow="never" style="border: none">
        <div class="vertical-radio">
          <el-radio v-model="type" :value="1">只编辑此课次</el-radio>
          <div class="remark">只调整当前选择的这个课次</div>
          <el-radio v-model="type" :value="2">编辑此课次及后续课次</el-radio>
          <div class="remark">只调整当前选择的这个课次</div>
        </div>
      </el-card>
    </el-space>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleDialogClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm"> 确定 </el-button>
      </div>
    </template>
  </el-dialog>

  <Schedule
    title="编辑排课"
    btn="保存"
    v-bind="$props"
    ref="scheduleRef"
    :from="from"
    @refreshPage="refreshParent"
    :refresh="true"
  />
</template>

<script setup>
import Schedule from "./schedule.vue";

const props = defineProps({
  // 关联课程id,多个用逗号分隔
  courseFilterIds: {
    type: String,
  },
  classId: {
    type: String,
  },
  classTitle: {
    type: String,
  },
  isVip: {
    type: String,
  },
});
// 变量--------------------------------------------------------------------------------------------------------------------
const dialogVisible = ref(false);
const scheduleRef = ref(null);

const data = reactive({
  currentItem: {},
});

const { currentItem } = toRefs(data);

const type = ref(1);
const from = ref("rollCall");

const emits = defineEmits(["refreshPage"]);

// 事件--------------------------------------------------------------------------------------------------------------------
function handleDialogOpen(item) {
  type.value = 1;
  dialogVisible.value = true;
  currentItem.value = item;
}

function handleDialogClose() {
  type.value = 1;
  dialogVisible.value = false;
}

function handleConfirm() {
  dialogVisible.value = false;
  if (type.value == 1) {
    from.value = "rollCall";
    scheduleRef.value.getScheduleDetailInRollCall(currentItem.value.id);
  } else {
    from.value = "schedule";
    scheduleRef.value.getScheduleDetail(currentItem.value.cofId);
  }
}

function refreshParent() {
  emits("refreshPage");
}

defineExpose({ handleDialogOpen }); // 用于父组件调用
</script>

<style lang="scss" scoped>
.el-form-item--default {
  margin-bottom: 5px;
}

.vertical-radio .el-radio-group,
.vertical-radio .el-radio {
  display: block;
  height: 20px;
}
.remark {
  color: rgb(153, 153, 153);
  margin: 5px 20px;
}
</style>
